package greetings

import (
	"fmt"
	"time"
)

func ChannelDemo() {

	ch := make(chan int, 10)
	go receiveFromChannel(ch)
	send2Channel(ch)
	time.Sleep(time.Second * 3)
	close(ch)
}

func receiveFromChannel(ch chan int) {

	//起一个线程，不停的消费这个channel的内容
	for {
		a := <-ch
		fmt.Println("receive from channel ", a)
	}
}

func send2Channel(ch chan int) {

	ch <- 10
	ch <- 10
	ch <- 10
	ch <- 10
}
